package com.zhuss.food.order;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.zhuss.bean.bo.food.order.CancelOrderBo;
import com.zhuss.bean.bo.food.order.FetchOrderBo;
import com.zhuss.bean.bo.food.order.ReceiveOrderBo;
import com.zhuss.bean.bo.food.order.wechat.CreateBoxOrderBo;
import com.zhuss.bean.bo.food.order.wechat.CreateStirfryOrderBo;
import com.zhuss.bean.bo.food.order.wechat.CreateTakeoutOrderBo;
import com.zhuss.bean.bo.food.order.wechat.CreateTopicBo;
import com.zhuss.common.OrderService;
import com.zhuss.common.Processor;
import com.zhuss.exception.WpsException;

/**
 * 订单操作service（基本操作）
 * @author zhushanshuo
 * @Date 2020/03/08 16:01
 *
 */
@Component("orderOperateService")
public class OrderOperateService implements OrderService<Void, Object> {
	
	@Autowired
	@Qualifier("takeoutOrderCreate")
	private Processor<Object, CreateTakeoutOrderBo> takeoutOrderCreate;
	
	@Autowired
	@Qualifier("stirfryOrderCreate")
	private Processor<Object, CreateStirfryOrderBo> stirfryOrderCreate;
	
	@Autowired
	@Qualifier("boxOrderCreate")
	private Processor<Object, CreateBoxOrderBo> boxOrderCreate;
	
	@Autowired
	@Qualifier("orderCancel")
	private Processor<Object, CancelOrderBo> orderCancel;
	
	@Autowired
	@Qualifier("orderFetch")
	private Processor<Object, FetchOrderBo> orderFetch;
	
	@Autowired
	@Qualifier("orderReceive")
	private Processor<Object, ReceiveOrderBo> orderReceive;
	
	@Autowired
	@Qualifier("topicCreate")
	private Processor<Object, CreateTopicBo> topicCreate;
	
	
	
	/**
	 * 创建外卖打包订单
	 */
	@Transactional(rollbackFor = Exception.class)
	public Void createTakeout(Object param) throws WpsException {
		
		CreateTakeoutOrderBo bo = (CreateTakeoutOrderBo) param;
		
		takeoutOrderCreate.process(bo);
		
		return null;
	}
	
	/**
	 * 创建点炒服务订单
	 */
	@Transactional(rollbackFor = Exception.class)
	public Void createStirfry(Object param) throws WpsException {
		
		CreateStirfryOrderBo bo = (CreateStirfryOrderBo) param;
		
		stirfryOrderCreate.process(bo);
		
		return null;
	}
	
	/**
	 * 创建晚餐预定订单
	 */
	@Transactional(rollbackFor = Exception.class)
	public Void createDinner(Object param) throws WpsException {
		
		createStirfry(param);
		
		return null;
	}
	
	/**
	 * 创建公务接待订单
	 */
	@Transactional(rollbackFor = Exception.class)
	public Void createBox(Object param) throws WpsException {
		
		CreateBoxOrderBo bo = (CreateBoxOrderBo) param;
		
		boxOrderCreate.process(bo);
		
		return null;
	}
	
	/**
	 * 取消
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public Void cancel(Object param) throws WpsException {
		
		CancelOrderBo bo = (CancelOrderBo) param;
		
		orderCancel.process(bo);
		
		return null;
	}
	
	/**
	 * 取餐
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public Void fetch(Object param) throws WpsException {
		
		FetchOrderBo bo = (FetchOrderBo) param;
		
		orderFetch.process(bo);
		
		return null;
	}
	
	/**
	 * 接单
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public Void receive(Object param) throws WpsException {
		
		ReceiveOrderBo bo = (ReceiveOrderBo) param;
		
		orderReceive.process(bo);
		
		return null;
	}
	
	/**
	 * 评价
	 */
	@Transactional(rollbackFor = Exception.class)
	public Void topic(Object param) throws WpsException {
		
		CreateTopicBo bo = (CreateTopicBo) param;
		
		topicCreate.process(bo);
		
		return null;
	}
	
}

